//
//  ZGWJiBingFengXianJiuZhengViewController.m
//  MyYiJianKangApp
//
//  Created by 张国文 on 16/6/3.
//  Copyright © 2016年 hangzhouyijiyin. All rights reserved.
//

#import "ZGWJiBingFengXianJiuZhengViewController.h"
#import "ZGWJiBingFengXianJiuZhengFirstTableViewCell.h"
#import "ZGWJiBingFengXianJiuZhengSecondTableViewCell.h"
#import "ZGWJiBingFengXianJiuZhengThirdTableViewCell.h"
#import "ZGWJiBingFengXianJiuZhengFourthTableViewCell.h"

@interface ZGWJiBingFengXianJiuZhengViewController ()<UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate, ZGWJiBingFengXianJiuZhengThireCellDelegate, ZGWJiBingFengXianJiuZhengFourThCellDelegate>

@property (nonatomic, strong) NSMutableArray *biaoTouNameArray; // 表头名字数组
@property (nonatomic, strong) NSMutableDictionary *biaoTouIsSelectDic; // 记录表头是否被点击

@property (nonatomic, strong) UITableView *jiBingJiuZhengTableView; // 疾病纠正tableView

@property (nonatomic, strong) NSMutableArray *userXinXiName; // 用户信息name

@property (nonatomic, strong) NSMutableDictionary *userXinXiNameDuiYingDic; // 用户信息name对应的dic

@property (nonatomic, strong) NSMutableArray *shengHuoXiGuanNameArray; //生活习惯name
@property (nonatomic, strong) NSMutableDictionary *shengHuoXiGuanNameDuiYingDic; // 生活习惯name对应的值

@property (nonatomic, strong) NSMutableArray *jiBingShiNameArray; // 疾病史name
@property (nonatomic, strong) NSMutableDictionary *jiBingShiNameDuiYingDic; // 疾病史name对应的值

@property (nonatomic, strong) NSIndexPath *tempIndexPath;

@property (nonatomic, strong) NSMutableArray *headerImageArray; // 表头图片数组

@property (nonatomic, strong) NSMutableArray *xiangGuanYinSuShengHuoXiGuanNameArray; // 相关致病因素的生活习惯name数组
@property (nonatomic, strong) NSMutableDictionary *xiangGuanYinSuShengHuoXiGuanDic; // 相关致病因素的生活习惯数组字典

@property (nonatomic, strong) NSMutableArray *xiangGuanYinSuJiBingShiNameArray; // 相关致病因素的疾病史name数组

@property (nonatomic, strong) NSMutableDictionary *xiangGuanYinSuJiBingDic; // 相关致病因素的疾病史字典

@property (nonatomic, strong) NSMutableDictionary *xiangGuanYinSuShengHuoXiGuanDuiYingCountDic; // 相关致病因素的生活习惯对应的数值

@property (nonatomic, strong) NSMutableDictionary *xiangGuanYinSuJiBingShiDuiYingCountDic; // 相关致病因素的疾病史对应的数值

@property (nonatomic, strong) NSMutableDictionary *userXinXiDuiYingCountDic; // 用户信息对应的数值字典

@property (nonatomic, assign) float jiuzhengFengXianZhiCount; // 纠正后风险值

@property (nonatomic, strong) NSString *ageText; // 年龄变化

@property (nonatomic, strong) NSString *shenGaoText; // 身高变化

@property (nonatomic, strong) NSString *tiZhongText; // 体重变化

@end

@implementation ZGWJiBingFengXianJiuZhengViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    // navi的修改
    [self changeNavigation];
    // 添加数据源
    [self addData];
    // 布局
    [self addMySubview];
}
// navi的修改
- (void)changeNavigation
{
    self.navigationItem.title = @"疾病风险纠正";
    UIImageView *leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
    leftImageView.image = [UIImage imageNamed:@"houtui"];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftImageView];
    UITapGestureRecognizer *leftTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(lastPage:)];
    [leftImageView addGestureRecognizer:leftTapGes];
    
    // 右方
    UIButton *finishButton = [UIButton buttonWithType:UIButtonTypeSystem];
    finishButton.frame = CGRectMake(0, 0, 50, 23);
    [finishButton setTitle:@"完成" forState:UIControlStateNormal];
    [finishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [finishButton addTarget:self action:@selector(finishFengXianJiuZheng:) forControlEvents:UIControlEventTouchUpInside];
    finishButton.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:k16Big];
    finishButton.layer.borderWidth = 1 * kAdjustParamater;
    finishButton.layer.borderColor = [[UIColor whiteColor] CGColor];
    finishButton.layer.cornerRadius = 6 * kAdjustParamater;
    finishButton.layer.masksToBounds = YES;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:finishButton];
    
}

#pragma mark - 返回上一页面
- (void)lastPage:(UITapGestureRecognizer *)tapGes
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 完成
- (void)finishFengXianJiuZheng:(UIButton *)button
{
    NSLog(@"完成风险值纠正");
   // self.ZgwJiBingFengXianJiuZheng(3);
    self.ZgwJiBingFengXianJiuZheng(self.jiuzhengFengXianZhiCount);
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 添加数据源
- (void)addData
{
    self.biaoTouNameArray = [NSMutableArray arrayWithObjects:@"我的基本资料", @"我的生活习惯", @"我的疾病史", nil];
    self.biaoTouIsSelectDic = [NSMutableDictionary dictionary];
    for (NSString *name in self.biaoTouNameArray) {
        [self.biaoTouIsSelectDic setValue:@"NO" forKey:name];
    }
    
    // 用户name
    self.userXinXiName = [NSMutableArray arrayWithObjects:@"性别", @"年龄", @"身高", @"体重", @"基因变异", @"家族史", @"BMI", @"体脂率", nil];
    // 用户信息字典
    self.userXinXiNameDuiYingDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"women", @"性别", @"31", @"年龄", @"170", @"身高", @"60", @"体重", @"1.8", @"基因变异", @"一人", @"家族史", @"20.7", @"BMI", @"26.6", @"体脂率", nil];
    // 用户生活习惯name
    self.shengHuoXiGuanNameArray = [NSMutableArray arrayWithObjects:@"吸烟", @"喝酒", @"喝茶", @"喝咖啡", @"熬夜", @"焦虑", @"压力山大", @"适当锻炼", @"三餐规律", @"合理膳食", @"睡眠充足", @"喝水适量", @"知足常乐", nil];
    // 用户生活习惯字典,分为1、2、3，1代表经常，2代表偶尔，3代表无
    self.shengHuoXiGuanNameDuiYingDic = [NSMutableDictionary dictionary];
    for (NSString *shengHuoXiGuanString in self.shengHuoXiGuanNameArray) {
        // 默认为无
        [self.shengHuoXiGuanNameDuiYingDic setValue:@"3" forKey:shengHuoXiGuanString];
    }
    // 用户疾病史
    self.jiBingShiNameArray = [NSMutableArray arrayWithObjects:@"高血压", @"糖尿病", @"高血脂", @"低血糖", @"贫血", @"肾病", @"肝病", @"胃病", @"心脏病", @"心肌炎", @"支气管炎", nil];
    // 用户疾病史字典,分为1、2、3，1代表严重，2代表轻微，3代表无
    self.jiBingShiNameDuiYingDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1", @"高血压", @"2", @"糖尿病", @"3", @"高血脂", @"3", @"低血糖", @"2", @"贫血", @"3", @"肾病", @"2", @"肝病", @"1", @"胃病", @"1", @"心脏病", @"2", @"心肌炎", @"1", @"支气管炎", nil];
    
    // 表头图片数组
    self.headerImageArray = [NSMutableArray arrayWithObjects:@"zhibingyinsu-jibingjiuzheng", @"jibenziliao-jibingjiuzheng", @"shenghuoxiguan-jibingjiuzheng", @"jibingshi-jibingjiuzheng", nil];
    
    
    // 提取相关致病因素需要展示的数据
    [self tiQuXiangGuanZhiBingYinSuData];
    
    [self simulateJiBingFengXianZhi];
}

#pragma mark - 提取相关致病因素需要展示的数据
- (void)tiQuXiangGuanZhiBingYinSuData
{
    // 吸烟的字典
    NSMutableDictionary *xiYanZiDian = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1.3", @"经常", @"1", @"偶尔", @"0.5", @"否", nil];
    self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic = [NSMutableDictionary dictionary];
    // 相关致病因素的生活习惯name数组、dic
    self.xiangGuanYinSuShengHuoXiGuanNameArray = [NSMutableArray array];
    self.xiangGuanYinSuShengHuoXiGuanDic = [NSMutableDictionary dictionary];
    for (NSString *shengHuoName in self.shengHuoXiGuanNameArray) {
        if ([shengHuoName isEqualToString:@"吸烟"]) {
            [self.xiangGuanYinSuShengHuoXiGuanNameArray addObject:shengHuoName];
            [self.xiangGuanYinSuShengHuoXiGuanDic setValue:[self.shengHuoXiGuanNameDuiYingDic valueForKey:shengHuoName] forKey:shengHuoName];
            [self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic setValue:xiYanZiDian forKey:shengHuoName];
        }
    }
    
    // 相关致病因素的疾病史的name数组、dic
    // 高血压字典
    NSMutableDictionary *gaoXueYaDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1.3", @"严重", @"1.2", @"轻微", @"1", @"无", nil];
    // 高血脂症字典
    NSMutableDictionary *gaoXueZhiZhengDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1.3", @"严重", @"1.2", @"轻微", @"1", @"无", nil];
    // 糖尿病字典
    NSMutableDictionary *tangNiaoBingDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1.3", @"严重", @"1.2", @"轻微", @"1", @"无", nil];
    // 相关字典对应的数值
    self.xiangGuanYinSuJiBingShiDuiYingCountDic = [NSMutableDictionary dictionary];
    self.xiangGuanYinSuJiBingShiNameArray = [NSMutableArray array];
    self.xiangGuanYinSuJiBingDic = [NSMutableDictionary dictionary];
    for (NSString *jiBingShiName in self.jiBingShiNameDuiYingDic) {
        if ([jiBingShiName isEqualToString:@"高血压"]) {
            [self.xiangGuanYinSuJiBingShiNameArray addObject:jiBingShiName];
            [self.xiangGuanYinSuJiBingDic setValue:[self.jiBingShiNameDuiYingDic valueForKey:jiBingShiName] forKey:jiBingShiName];
            [self.xiangGuanYinSuJiBingShiDuiYingCountDic setValue:gaoXueYaDic forKey:jiBingShiName];
        } else if ([jiBingShiName isEqualToString:@"高血脂"]) {
            [self.xiangGuanYinSuJiBingShiNameArray addObject:jiBingShiName];
            [self.xiangGuanYinSuJiBingDic setValue:[self.jiBingShiNameDuiYingDic valueForKey:jiBingShiName] forKey:jiBingShiName];
            [self.xiangGuanYinSuJiBingShiDuiYingCountDic setValue:gaoXueZhiZhengDic forKey:jiBingShiName];
        } else if ([jiBingShiName isEqualToString:@"糖尿病"]) {
            [self.xiangGuanYinSuJiBingShiNameArray addObject:jiBingShiName];
            [self.xiangGuanYinSuJiBingDic setValue:[self.jiBingShiNameDuiYingDic valueForKey:jiBingShiName] forKey:jiBingShiName];
            [self.xiangGuanYinSuJiBingShiDuiYingCountDic setValue:tangNiaoBingDic forKey:jiBingShiName];
        }
    }
    
    // 家族史对应数值字典
    NSMutableDictionary *jiaZuShiCountDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1.3", @"多人", @"1.2", @"一人", @"1", @"无", nil];
    // 年龄对应的数值字典
    NSMutableDictionary *nianLingCountDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"0.5", @"<30", @"1.2", @"30-50", @"1.3", @">50", nil];
    // BMI指数对应数值字典
    NSMutableDictionary *BMIZhiShuCountDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1.3", @">28", @"1.2", @"24-28", @"0.8", @"18.5-24", @"0.5", @"<18.5", nil];
    // 性别对应数值字典
    NSMutableDictionary *genderCountDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"1", @"男", @"0.5", @"女", nil];
    self.userXinXiDuiYingCountDic = [NSMutableDictionary dictionaryWithObjectsAndKeys:jiaZuShiCountDic, @"家族史", nianLingCountDic, @"年龄", BMIZhiShuCountDic, @"BMI指数",genderCountDic, @"性别",  nil];
//    NSLog(@"相关致病因素生活习惯对应的数值字典 = %@", self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic);
//    NSLog(@"相关致病因素疾病史对应的数值字典 = %@", self.xiangGuanYinSuJiBingShiDuiYingCountDic);
//    NSLog(@"用户信息对应的数值字典 = %@", self.userXinXiDuiYingCountDic);
//    
}

#pragma mark - 计算疾病风险值
- (void)simulateJiBingFengXianZhi
{
    // 家族史
    NSString *jiaZuShiString = [self.userXinXiNameDuiYingDic valueForKey:@"家族史"];
    float jiaZuShiCount = 0.0;
    if ([jiaZuShiString isEqualToString:@"多人"]) {
       jiaZuShiCount = [[[self.userXinXiDuiYingCountDic valueForKey:@"家族史"] valueForKey:@"多人"] floatValue];
    } else if ([jiaZuShiString isEqualToString:@"一人"]) {
        jiaZuShiCount = [[[self.userXinXiDuiYingCountDic valueForKey:@"家族史"] valueForKey:@"一人"] floatValue];
    } else if ([jiaZuShiString isEqualToString:@"无"]) {
        jiaZuShiCount = [[[self.userXinXiDuiYingCountDic valueForKey:@"家族史"] valueForKey:@"无"] floatValue];
    }
    
    // 性别
    NSString *genderString = [self.userXinXiNameDuiYingDic valueForKey:@"性别"];
    float genderCount = 0.0;
    if ([genderString isEqualToString:@"men"]) {
       genderCount = [[[self.userXinXiDuiYingCountDic valueForKey:@"性别"] valueForKey:@"男"] floatValue];
    } else if ([genderString isEqualToString:@"women"]) {
        genderCount = [[[self.userXinXiDuiYingCountDic valueForKey:@"性别"] valueForKey:@"女"] floatValue];
    }
    
    // BMI指数
    float BMIString = [[self.userXinXiNameDuiYingDic valueForKey:@"BMI"] floatValue];
    float BMICount = 0.0;
    if (BMIString > 28) {
       BMICount = [[[self.userXinXiDuiYingCountDic valueForKey:@"BMI指数"] valueForKey:@">28"] floatValue];
    } else if (BMIString > 24 && BMIString <=28) {
        BMICount = [[[self.userXinXiDuiYingCountDic valueForKey:@"BMI指数"] valueForKey:@"24-28"] floatValue];
    } else if (BMIString >= 18.5 && BMIString <= 24) {
        BMICount = [[[self.userXinXiDuiYingCountDic valueForKey:@"BMI指数"] valueForKey:@"18.5-24"] floatValue];
    } else if (BMIString < 18.5) {
        BMICount = [[[self.userXinXiDuiYingCountDic valueForKey:@"BMI指数"] valueForKey:@"<18.5"] floatValue];
    }
    
    // 年龄
    float ageString = [[self.userXinXiNameDuiYingDic valueForKey:@"年龄"] floatValue];
    float ageCount = 0.0;
    if (ageString < 30) {
       ageCount = [[[self.userXinXiDuiYingCountDic valueForKey:@"年龄"] valueForKey:@"<30"] floatValue];
    } else if (ageString >= 30 && ageString < 50) {
        ageCount = [[[self.userXinXiDuiYingCountDic valueForKey:@"年龄"] valueForKey:@"30-50"] floatValue];
    } else if (ageString >= 50) {
        ageCount = [[[self.userXinXiDuiYingCountDic valueForKey:@"年龄"] valueForKey:@">50"] floatValue];
    }
    
    // 吸烟
    NSString *xiYanString = [self.shengHuoXiGuanNameDuiYingDic valueForKey:@"吸烟"];
    float xiYanCount = 0.0;
    if ([xiYanString isEqualToString:@"1"]) {
       xiYanCount = [[[self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic valueForKey:@"吸烟"] valueForKey:@"经常"] floatValue];
    } else if ([xiYanString isEqualToString:@"2"]) {
        xiYanCount = [[[self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic valueForKey:@"吸烟"] valueForKey:@"偶尔"] floatValue];
    } else if ([xiYanString isEqualToString:@"3"]) {
        xiYanCount = [[[self.xiangGuanYinSuShengHuoXiGuanDuiYingCountDic valueForKey:@"吸烟"] valueForKey:@"否"] floatValue];
    }
    
    // 高血压
    NSString *gaoXueYaString = [self.jiBingShiNameDuiYingDic valueForKey:@"高血压"];
    float gaoXueCount = 0.0;
    if ([gaoXueYaString isEqualToString:@"1"]) {
       gaoXueCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"高血压"] valueForKey:@"严重"] floatValue];
    } else if ([gaoXueYaString isEqualToString:@"2"]) {
        gaoXueCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"高血压"] valueForKey:@"轻微"] floatValue];
    } else if ([gaoXueYaString isEqualToString:@"3"]) {
        gaoXueCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"高血压"] valueForKey:@"无"] floatValue];
    }
    
    // 高血脂
    NSString *gaoXueZhiString = [self.jiBingShiNameDuiYingDic valueForKey:@"高血脂"];
    float gaoXueZhiCount = 0.0;
    if ([gaoXueZhiString isEqualToString:@"1"]) {
        gaoXueZhiCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"高血脂"] valueForKey:@"严重"] floatValue];
    } else if ([gaoXueZhiString isEqualToString:@"2"]) {
        gaoXueZhiCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"高血脂"] valueForKey:@"轻微"] floatValue];
    } else if ([gaoXueZhiString isEqualToString:@"3"]) {
        gaoXueZhiCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"高血脂"] valueForKey:@"无"] floatValue];
    }
    
    // 糖尿病
    NSString *tangNiaoBingString = [self.jiBingShiNameDuiYingDic valueForKey:@"糖尿病"];
    float tangNiaoBingCount = 0.0;
    if ([tangNiaoBingString isEqualToString:@"1"]) {
        tangNiaoBingCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"糖尿病"] valueForKey:@"严重"] floatValue];
    } else if ([tangNiaoBingString isEqualToString:@"2"]) {
        tangNiaoBingCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"糖尿病"] valueForKey:@"轻微"] floatValue];
    } else if ([tangNiaoBingString isEqualToString:@"3"]) {
        tangNiaoBingCount = [[[self.xiangGuanYinSuJiBingShiDuiYingCountDic valueForKey:@"糖尿病"] valueForKey:@"无"] floatValue];
    }
    
//    NSLog(@"家族史数值 = %f", jiaZuShiCount);
//    NSLog(@"年龄数值 = %f", ageCount);
//    NSLog(@"BMI数值 = %f", BMICount);
//    NSLog(@"性别数值 = %f", genderCount);
//    NSLog(@"吸烟数值 = %f", xiYanCount);
//    NSLog(@"高血压数值 = %f", gaoXueCount);
//    NSLog(@"高血脂数值 = %f", gaoXueZhiCount);
//    NSLog(@"糖尿病数值 = %f", tangNiaoBingCount);
    // 基因变异指数
    float jiYinBianYiCount = [[self.userXinXiNameDuiYingDic valueForKey:@"基因变异"] floatValue];
    self.jiuzhengFengXianZhiCount = jiYinBianYiCount * jiaZuShiCount * ageCount * BMICount * genderCount * xiYanCount * gaoXueCount * gaoXueZhiCount * tangNiaoBingCount;
    NSLog(@"纠正风险值数值 = %f", self.jiuzhengFengXianZhiCount);
}

#pragma mark - 布局
- (void)addMySubview
{
    self.jiBingJiuZhengTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 64) style:UITableViewStylePlain];
    self.jiBingJiuZhengTableView.backgroundColor = [UIColor whiteColor];
    self.jiBingJiuZhengTableView.dataSource = self;
    self.jiBingJiuZhengTableView.delegate = self;
    self.jiBingJiuZhengTableView.bounces = NO;
    self.jiBingJiuZhengTableView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:_jiBingJiuZhengTableView];
    
}



- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    } else {
        NSString *name = self.biaoTouNameArray[section - 1];
        NSString *isSelect = [self.biaoTouIsSelectDic valueForKey:name];
        if ([isSelect isEqualToString:@"YES"]) {
            return 1;
        } else if ([isSelect isEqualToString:@"NO"]) {
            return 0;
        }
    }
    
    return 0;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        // 相关致病因素cell
        static NSString *identifier = @"firstCell";
        ZGWJiBingFengXianJiuZhengFirstTableViewCell *firstCell = [[ZGWJiBingFengXianJiuZhengFirstTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier withUserXinXiNameArray:self.userXinXiName userXinXiDic:self.userXinXiNameDuiYingDic shengHuoXiGuanNameArray:self.xiangGuanYinSuShengHuoXiGuanNameArray shengHuoXiGuanDic:self.xiangGuanYinSuShengHuoXiGuanDic jiBingShiNameArray:self.xiangGuanYinSuJiBingShiNameArray jiBingShiDic:self.xiangGuanYinSuJiBingDic];
        firstCell.selectionStyle = UITableViewCellSelectionStyleNone;
        [firstCell.duoRenButtonOfJiaZuShi addTarget:self action:@selector(duoRenOfFirstCell:) forControlEvents:UIControlEventTouchUpInside];
        [firstCell.yiRenButtonOfJiaZuShi addTarget:self action:@selector(yiRenOfFirstCell:) forControlEvents:UIControlEventTouchUpInside];
        [firstCell.wuButtonOfJiaZuShi addTarget:self action:@selector(wuButtonOfFirstCell:) forControlEvents:UIControlEventTouchUpInside];
        return firstCell;
    } else if (indexPath.section == 1) {
        self.tempIndexPath = indexPath;
        // 我的基本资料
        static NSString *identifier = @"secondCell";
        ZGWJiBingFengXianJiuZhengSecondTableViewCell *secondCell = [[ZGWJiBingFengXianJiuZhengSecondTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier withUserXinXiDic:self.userXinXiNameDuiYingDic];
        secondCell.selectionStyle = UITableViewCellSelectionStyleNone;
        [secondCell.nanButton addTarget:self action:@selector(nanOfSecondCell:) forControlEvents:UIControlEventTouchUpInside];
        [secondCell.nvButton addTarget:self action:@selector(nvOfSecondCell:) forControlEvents:UIControlEventTouchUpInside];
        secondCell.ageTF.delegate = self;
        secondCell.ageTF.tag = 300;
        [secondCell.ageTF addTarget:self action:@selector(textChangeOfSecondCell1:) forControlEvents:UIControlEventAllEditingEvents];
        // 为年龄添加辅助视图
        // 构建辅助视图
        UIView *seorryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 25 * kAdjustParamater)];
        seorryView.backgroundColor = [UIColor colorWithRed:249 / 255.0 green:249 / 255.0 blue:249 / 255.0 alpha:1];
        
        UILabel *grayLineOnSeorryView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 1 * kAdjustParamater)];
        grayLineOnSeorryView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
        [seorryView addSubview:grayLineOnSeorryView];
        
        // 完成button
        UIButton *textViewFinishButton = [UIButton buttonWithType:UIButtonTypeSystem];
        textViewFinishButton.frame = CGRectMake(334  *kAdjustParamater, 5 * kAdjustParamater, 30 * kAdjustParamater, 15 * kAdjustParamater);
        textViewFinishButton.layer.cornerRadius = 2 * kAdjustParamater;
        [textViewFinishButton setTitle:@"完成" forState:UIControlStateNormal];
        [textViewFinishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        textViewFinishButton.backgroundColor = kCyanColor;
        textViewFinishButton.titleLabel.font = [UIFont systemFontOfSize:k13Big];
        [textViewFinishButton addTarget:self action:@selector(ageFinish:) forControlEvents:UIControlEventTouchUpInside];
        [seorryView addSubview:textViewFinishButton];
        secondCell.ageTF.inputAccessoryView = seorryView;
        
        secondCell.shenGaoTF.delegate = self;
        secondCell.shenGaoTF.tag = 301;
        [secondCell.shenGaoTF addTarget:self action:@selector(textChangeOfSecondCell2:) forControlEvents:UIControlEventAllEditingEvents];
        // 为身高添加辅助视图
        // 构建辅助视图
        UIView *shenGaoseorryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 25 * kAdjustParamater)];
        shenGaoseorryView.backgroundColor = [UIColor colorWithRed:249 / 255.0 green:249 / 255.0 blue:249 / 255.0 alpha:1];
        
        UILabel *grayLineOnShenGaoSeorryView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 1 * kAdjustParamater)];
        grayLineOnShenGaoSeorryView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
        [shenGaoseorryView addSubview:grayLineOnShenGaoSeorryView];
        
        // 完成button
        UIButton *shenGaoTextViewFinishButton = [UIButton buttonWithType:UIButtonTypeSystem];
        shenGaoTextViewFinishButton.frame = CGRectMake(334  *kAdjustParamater, 5 * kAdjustParamater, 30 * kAdjustParamater, 15 * kAdjustParamater);
        shenGaoTextViewFinishButton.layer.cornerRadius = 2 * kAdjustParamater;
        [shenGaoTextViewFinishButton setTitle:@"完成" forState:UIControlStateNormal];
        [shenGaoTextViewFinishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        shenGaoTextViewFinishButton.backgroundColor = kCyanColor;
        shenGaoTextViewFinishButton.titleLabel.font = [UIFont systemFontOfSize:k13Big];
        [shenGaoTextViewFinishButton addTarget:self action:@selector(shenGaoFinish:) forControlEvents:UIControlEventTouchUpInside];
        [shenGaoseorryView addSubview:shenGaoTextViewFinishButton];
        secondCell.shenGaoTF.inputAccessoryView = shenGaoseorryView;
        
        
        secondCell.tiZhongTF.delegate = self;
        secondCell.tiZhongTF.tag = 302;
        [secondCell.tiZhongTF addTarget:self action:@selector(textChangeOfSecondCell3:) forControlEvents:UIControlEventAllEditingEvents];
        // 为体重添加辅助视图
        // 构建辅助视图
        UIView *tiZhongseorryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 25 * kAdjustParamater)];
        tiZhongseorryView.backgroundColor = [UIColor colorWithRed:249 / 255.0 green:249 / 255.0 blue:249 / 255.0 alpha:1];
        
        UILabel *grayLineOnTiZhongSeorryView = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 1 * kAdjustParamater)];
        grayLineOnTiZhongSeorryView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
        [tiZhongseorryView addSubview:grayLineOnTiZhongSeorryView];
        
        // 完成button
        UIButton *tiZhongTextViewFinishButton = [UIButton buttonWithType:UIButtonTypeSystem];
        tiZhongTextViewFinishButton.frame = CGRectMake(334  *kAdjustParamater, 5 * kAdjustParamater, 30 * kAdjustParamater, 15 * kAdjustParamater);
        tiZhongTextViewFinishButton.layer.cornerRadius = 2 * kAdjustParamater;
        [tiZhongTextViewFinishButton setTitle:@"完成" forState:UIControlStateNormal];
        [tiZhongTextViewFinishButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        tiZhongTextViewFinishButton.backgroundColor = kCyanColor;
        tiZhongTextViewFinishButton.titleLabel.font = [UIFont systemFontOfSize:k13Big];
        [tiZhongTextViewFinishButton addTarget:self action:@selector(tiZhongFinish:) forControlEvents:UIControlEventTouchUpInside];
        [tiZhongseorryView addSubview:tiZhongTextViewFinishButton];
        secondCell.tiZhongTF.inputAccessoryView = tiZhongseorryView;
        return secondCell;
    } else if (indexPath.section == 2) {
        // 我的生活习惯
        static NSString *identifier = @"thirdCell";
        ZGWJiBingFengXianJiuZhengThirdTableViewCell *thirdCell = [[ZGWJiBingFengXianJiuZhengThirdTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier withShengHuoXiGuanNameArray:self.shengHuoXiGuanNameArray shengHuoXiGuanDic:self.shengHuoXiGuanNameDuiYingDic];
        thirdCell.selectionStyle = UITableViewCellSelectionStyleNone;
        thirdCell.delegate = self;
        return thirdCell;
    } else if (indexPath.section == 3) {
        // 我的疾病史
        static NSString *identifier = @"fourthCell";
        ZGWJiBingFengXianJiuZhengFourthTableViewCell *fourThCell = [[ZGWJiBingFengXianJiuZhengFourthTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier withJiBingShiNameArray:self.jiBingShiNameArray jiBingShiDic:self.jiBingShiNameDuiYingDic];
        fourThCell.delegate = self;
        fourThCell.selectionStyle = UITableViewCellSelectionStyleNone;
        return fourThCell;
    }
    // 没有这种情况
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        // 相关致病因素
        ZGWJiBingFengXianJiuZhengFirstTableViewCell *firstCell = (ZGWJiBingFengXianJiuZhengFirstTableViewCell *)[self tableView:self.jiBingJiuZhengTableView cellForRowAtIndexPath:indexPath];
        return firstCell.bottomGrayLine.bottom;
    } else if (indexPath.section == 1) {
        // 我的基本资料
        ZGWJiBingFengXianJiuZhengSecondTableViewCell *secondCell = (ZGWJiBingFengXianJiuZhengSecondTableViewCell *)[self tableView:self.jiBingJiuZhengTableView cellForRowAtIndexPath:indexPath];
        return secondCell.bottomGrayLabel.bottom;
    } else if (indexPath.section == 2) {
        // 我的生活习惯
        ZGWJiBingFengXianJiuZhengThirdTableViewCell *thirdCell = (ZGWJiBingFengXianJiuZhengThirdTableViewCell *)[self tableView:self.jiBingJiuZhengTableView cellForRowAtIndexPath:indexPath];
        return thirdCell.bottomGrayLine.bottom;
    } else if (indexPath.section == 3) {
        // 我的疾病史
        ZGWJiBingFengXianJiuZhengFourthTableViewCell *fourCell = (ZGWJiBingFengXianJiuZhengFourthTableViewCell *)[self tableView:self.jiBingJiuZhengTableView cellForRowAtIndexPath:indexPath];
        return fourCell.bottomGrayLine.bottom;
    }
    // 没有这种情况
    return 0 * kAdjustParamater;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        UIView *headerBackGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 67 * kAdjustParamater)];
        headerBackGroundView.backgroundColor = [UIColor whiteColor];
        
        // 标题之前的箭头
        UIImageView *biaoTiBeforeImageV = [[UIImageView alloc] initWithFrame:CGRectMake(23 * kAdjustParamater, 25 * kAdjustParamater, 16 * kAdjustParamater, 16 * kAdjustParamater)];
        biaoTiBeforeImageV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
        biaoTiBeforeImageV.layer.cornerRadius = biaoTiBeforeImageV.width / 2;
        biaoTiBeforeImageV.image = [UIImage imageNamed:self.headerImageArray[section]];
        [headerBackGroundView addSubview:biaoTiBeforeImageV];
        
        // 标题
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(biaoTiBeforeImageV.right + 6 * kAdjustParamater, 23 * kAdjustParamater, 200 * kAdjustParamater, 20 * kAdjustParamater)];
        titleLabel.text = @"冠心病相关致病因素";
     //   titleLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
        titleLabel.textColor = kCyanColor;
        titleLabel.textAlignment = NSTextAlignmentLeft;
        titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:k20Big];
        [headerBackGroundView addSubview:titleLabel];
        
        // 添加灰色条
        UILabel *grayLineOnHeaderBottom = [[UILabel alloc] initWithFrame:CGRectMake(0, 66 * kAdjustParamater, kScreenWidth, 1 * kAdjustParamater)];
        grayLineOnHeaderBottom.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.07];
        [headerBackGroundView addSubview:grayLineOnHeaderBottom];
        
        return headerBackGroundView;
    } else {
        UIView *headerBackGroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 67 * kAdjustParamater)];
        headerBackGroundView.userInteractionEnabled = YES;
        headerBackGroundView.tag = 200 + section;
        headerBackGroundView.backgroundColor = [UIColor whiteColor];
        
        UITapGestureRecognizer *headerBackGroundViewTapGes = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(headerBackGroundViewGes:)];
        [headerBackGroundView addGestureRecognizer:headerBackGroundViewTapGes];
        
        // 标题之前的箭头
        UIImageView *biaoTiBeforeImageV = [[UIImageView alloc] initWithFrame:CGRectMake(23 * kAdjustParamater, 25 * kAdjustParamater, 16 * kAdjustParamater, 16 * kAdjustParamater)];
        biaoTiBeforeImageV.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
        biaoTiBeforeImageV.layer.cornerRadius = biaoTiBeforeImageV.width / 2;
        biaoTiBeforeImageV.image = [UIImage imageNamed:self.headerImageArray[section]];
        [headerBackGroundView addSubview:biaoTiBeforeImageV];
        
        // 标题
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(biaoTiBeforeImageV.right + 6 * kAdjustParamater, 23 * kAdjustParamater, 200 * kAdjustParamater, 20 * kAdjustParamater)];
        titleLabel.text = self.biaoTouNameArray[section - 1];
    //    titleLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.1];
        titleLabel.textColor = kCyanColor;
        titleLabel.textAlignment = NSTextAlignmentLeft;
        titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:k20Big];
        [headerBackGroundView addSubview:titleLabel];
        
        // 箭头
        UIImageView *jianTouImageV =  [[UIImageView alloc] initWithFrame:CGRectMake(340 * kAdjustParamater, 20 * kAdjustParamater, 25 * kAdjustParamater, 25 * kAdjustParamater)];
        NSString *name = self.biaoTouNameArray[section -1];
        // 是否点击
        NSString *isSelect = [self.biaoTouIsSelectDic valueForKey:name];
        if ([isSelect isEqualToString:@"YES"]) {
            jianTouImageV.image = [UIImage imageNamed:@"cyanjiantou-createGroup"];
        } else if ([isSelect isEqualToString:@"NO"]) {
             jianTouImageV.image = [UIImage imageNamed:@"huisejiantou-createGroup"];
        }
        [headerBackGroundView addSubview:jianTouImageV];
        
        // 添加灰色条
        UILabel *grayLineOnHeaderBottom = [[UILabel alloc] initWithFrame:CGRectMake(0, 66 * kAdjustParamater, kScreenWidth, 1 * kAdjustParamater)];
        grayLineOnHeaderBottom.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.07];
        [headerBackGroundView addSubview:grayLineOnHeaderBottom];
        
        return headerBackGroundView;
    }
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 67 * kAdjustParamater;
}

#pragma mark - 点击表头
- (void)headerBackGroundViewGes:(UITapGestureRecognizer *)tapGes
{
    NSLog(@"点击了第%ld行", tapGes.view.tag - 201);
    NSString *name = self.biaoTouNameArray[tapGes.view.tag - 201];
    NSString *isSelect = [self.biaoTouIsSelectDic valueForKey:name];
    if ([isSelect isEqualToString:@"YES"]) {
        [self.biaoTouIsSelectDic setValue:@"NO" forKey:name];
    } else if ([isSelect isEqualToString:@"NO"]) {
        [self.biaoTouIsSelectDic setValue:@"YES" forKey:name];
    }
    [self.jiBingJiuZhengTableView reloadData];
}

#pragma mark - 致病因素cell
- (void)duoRenOfFirstCell:(UIButton *)button
{
    NSLog(@"多人");
    [self.userXinXiNameDuiYingDic setValue:@"多人" forKey:@"家族史"];
    [self.jiBingJiuZhengTableView reloadData];
    // 计算纠正风险值
    [self simulateJiBingFengXianZhi];
}

- (void)yiRenOfFirstCell:(UIButton *)button
{
    NSLog(@"一人");
    [self.userXinXiNameDuiYingDic setValue:@"一人" forKey:@"家族史"];
    [self.jiBingJiuZhengTableView reloadData];
    // 计算纠正风险值
    [self simulateJiBingFengXianZhi];
}

- (void)wuButtonOfFirstCell:(UIButton *)button
{
    NSLog(@"无人");
    [self.userXinXiNameDuiYingDic setValue:@"无" forKey:@"家族史"];
    [self.jiBingJiuZhengTableView reloadData];
    // 计算纠正风险值
    [self simulateJiBingFengXianZhi];
}

#pragma mark - 我的基本资料
- (void)nanOfSecondCell:(UIButton *)button
{
    NSLog(@"男");
    [self.userXinXiNameDuiYingDic setValue:@"men" forKey:@"性别"];
    [self.jiBingJiuZhengTableView reloadData];
    // 计算纠正风险值
    [self simulateJiBingFengXianZhi];
    // 计算体脂率
    [self simulateTiZhiLv];
}

- (void)nvOfSecondCell:(UIButton *)button
{
    NSLog(@"女");
    [self.userXinXiNameDuiYingDic setValue:@"women" forKey:@"性别"];
    [self.jiBingJiuZhengTableView reloadData];
    // 计算纠正风险值
    [self simulateJiBingFengXianZhi];
    // 计算体脂率
    [self simulateTiZhiLv];
}

#pragma mark - 我的基本资料TFdelegate

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    if (textField.tag == 302) {
        NSString *resultString = [textField.text substringToIndex:textField.text.length - 2];
        textField.text = resultString;
        
    }
}

- (void)textChangeOfSecondCell1:(UITextField *)textField
{
    
    NSLog(@"年龄tf = %@", textField.text);
    self.ageText = textField.text;
}

- (void)textChangeOfSecondCell2:(UITextField *)textField
{
    

    NSLog(@"身高tf = %@", textField.text);
    self.shenGaoText = textField.text;
}

- (void)textChangeOfSecondCell3:(UITextField *)textField
{
    
    NSLog(@"体重tf = %@", textField.text);
    if ([textField.text containsString:@"kg"]) {
        NSString *resultString = [textField.text substringToIndex:textField.text.length - 2];
        self.tiZhongText = resultString;
    } else {
        self.tiZhongText = textField.text;
    }
    
}

- (void)ageFinish:(UIButton *)button
{
    NSLog(@"保存年龄");
   
    if ([self.ageText containsString:@" "]) {
        NSLog(@"不能输入空格");
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"不能输入空格" ToView:self];
    } else {
        // 判断textField是否是数字
    
        if (![self isFloat:self.ageText]) {
            
            NSLog(@"不是数字");
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"只能输入数字，请重新输入" ToView:self];
            
            
        } else {
            NSLog(@"是数字");
            NSLog(@"保存年龄");
            [self.userXinXiNameDuiYingDic setValue:self.ageText forKey:@"年龄"];
            [self.jiBingJiuZhengTableView reloadData];
            
            // 进行BMI的计算
            [self simulateBMI];
            // 计算体脂率
            [self simulateTiZhiLv];
            [self.jiBingJiuZhengTableView reloadData];
            // 计算纠正风险值
            [self simulateJiBingFengXianZhi];
        }
    }
        // 取消第一响应者
    [self.view endEditing:YES];
      //  [self.navigationController.view endEditing:YES];

   
}
    

- (void)shenGaoFinish:(UIButton *)button
{
    NSLog(@"保存身高");
    if ([self.shenGaoText containsString:@" "]) {
        NSLog(@"不能输入空格");
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"不能输入空格" ToView:self];
    } else {
        // 判断textField是否是数字
        
        if (![self isFloat:self.shenGaoText]) {
            
            NSLog(@"不是数字");
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"只能输入数字，请重新输入" ToView:self];
            
            
        } else {
            NSLog(@"是数字");
            NSLog(@"保存年龄");
            [self.userXinXiNameDuiYingDic setValue:self.shenGaoText forKey:@"身高"];
            [self.jiBingJiuZhengTableView reloadData];
            
            // 进行BMI的计算
            [self simulateBMI];
            // 计算体脂率
            [self simulateTiZhiLv];
            [self.jiBingJiuZhengTableView reloadData];
            // 计算纠正风险值
            [self simulateJiBingFengXianZhi];
        }
    }
    // 取消第一响应者
    [self.view endEditing:YES];
   // [self.navigationController.view endEditing:YES];
}

- (void)tiZhongFinish:(UIButton *)button
{
    NSLog(@"保存体重");
    if ([self.tiZhongText containsString:@" "]) {
        NSLog(@"不能输入空格");
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"不能输入空格" ToView:self];
    } else {
        // 判断textField是否是数字
        
        if (![self isFloat:self.tiZhongText]) {
            
            NSLog(@"不是数字");
            [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"只能输入数字，请重新输入" ToView:self];
            
            
        } else {
            NSLog(@"是数字");
            NSLog(@"保存年龄");
            [self.userXinXiNameDuiYingDic setValue:self.tiZhongText forKey:@"体重"];
            [self.jiBingJiuZhengTableView reloadData];
            
            // 进行BMI的计算
            [self simulateBMI];
            // 计算体脂率
            [self simulateTiZhiLv];
            [self.jiBingJiuZhengTableView reloadData];
            // 计算纠正风险值
            [self simulateJiBingFengXianZhi];
        }
    }
    // 取消第一响应者
    [self.view endEditing:YES];
    //[self.navigationController.view endEditing:YES];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    NSLog(@"textField = %@", textField.text);
    if ([textField.text containsString:@" "]) {
        NSLog(@"不能输入空格");
        [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"不能输入空格" ToView:self];
    } else {
        // 判断textField是否是数字
        
        if (![self isFloat:textField.text]) {
            
                NSLog(@"不是数字");
                [[JiaZaiAnimationHandle shareJiaZaiAnimationHandle] addAlertTitle:@"警告" Content:@"只能输入数字，请重新输入" ToView:self];
            
            
        } else {
            NSLog(@"是数字");
            if (textField.tag == 300) {
                NSLog(@"保存年龄");
                [self.userXinXiNameDuiYingDic setValue:textField.text forKey:@"年龄"];
                [self.jiBingJiuZhengTableView reloadData];
            } else if (textField.tag == 301) {
                NSLog(@"保存身高");
                [self.userXinXiNameDuiYingDic setValue:textField.text forKey:@"身高"];
                [self.jiBingJiuZhengTableView reloadData];
            } else if (textField.tag == 302) {
                NSLog(@"保存体重");
                [self.userXinXiNameDuiYingDic setValue:textField.text forKey:@"体重"];
                [self.jiBingJiuZhengTableView reloadData];
            }
            
            // 进行BMI的计算
            [self simulateBMI];
            // 计算体脂率
            [self simulateTiZhiLv];
            [self.jiBingJiuZhengTableView reloadData];
            // 计算纠正风险值
            [self simulateJiBingFengXianZhi];
        }
    }
   
    [textField resignFirstResponder];
    return YES;
}

// 判断是否是整形
- (BOOL)isInt:(NSString *)string
{
    NSScanner *scan = [NSScanner scannerWithString:string];
    int val;
    return [scan scanInt:&val] && [scan isAtEnd];
}

// 判断是否为浮点型
- (BOOL)isFloat:(NSString *)string
{
    NSScanner *scan = [NSScanner scannerWithString:string];
    float val;
    return [scan scanFloat:&val] && [scan isAtEnd];
}

#pragma mark - BMI计算
- (void)simulateBMI
{
    float tiZhong = [[self.userXinXiNameDuiYingDic valueForKey:@"体重"] floatValue];
    float shenGao = [[self.userXinXiNameDuiYingDic valueForKey:@"身高"] floatValue] / 100;
    float BMI = tiZhong / (shenGao * shenGao);
    NSLog(@"shengao = %f", shenGao);
    NSLog(@"BMI = %f", BMI);
    NSString *BMIString = [NSString stringWithFormat:@"%f", BMI];
    [self.userXinXiNameDuiYingDic setValue:BMIString forKey:@"BMI"];
  //  NSLog(@"self.userXinXiDic = %@", self.userXinXiNameDuiYingDic);
}

#pragma mark - 计算体脂率
- (void)simulateTiZhiLv
{
    // BMI
    float BMICount = [[self.userXinXiNameDuiYingDic valueForKey:@"BMI"] floatValue];
    // 性别
    NSString *genderString = [self.userXinXiNameDuiYingDic valueForKey:@"性别"];
    float genderCount = 0.0;
    if ([genderString isEqualToString:@"men"]) {
        genderCount = 1.0;
    } else if ([genderString isEqualToString:@"women"]) {
        genderCount = 0.0;
    }
    // 年龄
    float ageCount = [[self.userXinXiNameDuiYingDic valueForKey:@"年龄"] floatValue];
    float tiZhiCount = 1.2 * BMICount + 0.23 * ageCount - 5.4 - 10.8 * genderCount;
    NSLog(@"体脂率 = %f", tiZhiCount);
    [self.userXinXiNameDuiYingDic setValue:[NSString stringWithFormat:@"%f", tiZhiCount] forKey:@"体脂率"];
}


#pragma mark - 生活习惯点击回调
- (void)clickTag:(NSInteger)tag withShengHuoXiGuanName:(NSString *)name
{
    if (tag >=100 && tag < 200) {
        // 说明点击的经常
        NSLog(@"点击的第%ld个经常--生活习惯", tag - 100);
        [self.shengHuoXiGuanNameDuiYingDic setValue:@"1" forKey:name];
    } else if (tag >=200 && tag < 300) {
        // 说明点击的偶尔
        NSLog(@"点击的第%ld个偶尔--生活习惯", tag - 200);
        [self.shengHuoXiGuanNameDuiYingDic setValue:@"2" forKey:name];
    } else if (tag >=300) {
        // 说明点击的无
        NSLog(@"点击的第%ld个无--生活习惯", tag - 300);
        [self.shengHuoXiGuanNameDuiYingDic setValue:@"3" forKey:name];
    }
    NSLog(@"生活习惯的名字 = %@", name);
    // 计算纠正风险值
    [self simulateJiBingFengXianZhi];
    // 重新提取展示在第一个cell上的数据
    [self tiQuXiangGuanZhiBingYinSuData];
    [self.jiBingJiuZhengTableView reloadData];
    
}

#pragma mark - 疾病史的点击回调
- (void)clickTag:(NSInteger)tag withJiBingName:(NSString *)jiBingname
{
    if (tag >=100 && tag < 200) {
        // 说明点击的严重
       NSLog(@"点击的第%ld个严重--疾病史", tag - 100);
        [self.jiBingShiNameDuiYingDic setValue:@"1" forKey:jiBingname];
    } else if (tag >=200 && tag < 300) {
        // 说明点击的轻微
        NSLog(@"点击的第%ld个轻微--疾病史", tag - 100);
        [self.jiBingShiNameDuiYingDic setValue:@"2" forKey:jiBingname];
    } else if (tag >=300) {
        // 说明点击的无
        NSLog(@"点击的第%ld个无--疾病史", tag - 100);
        [self.jiBingShiNameDuiYingDic setValue:@"3" forKey:jiBingname];
    }
    NSLog(@"疾病史的名字:%@", jiBingname);
    // 计算纠正风险值
    [self simulateJiBingFengXianZhi];
    // 重新提取展示在第一个cell上的数据
    [self tiQuXiangGuanZhiBingYinSuData];
    [self.jiBingJiuZhengTableView reloadData];
   
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
